package com.atguigu.lease.common.utils;

import java.util.Random;

/**
 * Description:
 * 随机验证码构造工具类
 * 用于web-app模块下，返回一个短信验证码的随机code
 * @author Yanxinhao on 2024/11/21
 */
public class VerifyCodeUtil {
    public static String getVerifyCode(int length){
        //1.创建一个字符串构建器
        StringBuilder builder = new StringBuilder();
        //2.创建一个随机数对象
        Random random = new Random();
        //3.根据传来的验证码长度，进行循环拼接
        for (int i = 0; i < length; i++) {
            builder.append(random.nextInt(10));
        }
        return builder.toString();
    }
}